package com.huang.CAS.LongAdder;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

public class LongAdderDemo {
    public static void main(String[] args) {

        LongAdder longAdder = new LongAdder();  //只能叠加
        longAdder.add(1);
        longAdder.add(1);
        longAdder.add(1);
        System.out.println(longAdder.longValue());


        LongAccumulator longAccumulator = new LongAccumulator((a, b) -> {
            return a-b;   //自定义a b的计算
        },
                20);  //自定义初始值
        longAccumulator.accumulate(1);
        longAccumulator.accumulate(1);
        System.out.println(longAccumulator.longValue());
    }
}
